package com.lz.repository.xjl.impl;

import com.lz.entity.TemporaryCarParts;
import com.lz.entity.UpholsteryType;
import com.lz.repository.xjl.UpholsteryTypeDao;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate4.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;


import javax.annotation.Resource;
import java.util.List;

/**
 * @author 徐建林
 * @date 2018/10/26 11:03
 */
@Repository
public class UpholsteryTypeDaoImpl  implements UpholsteryTypeDao {
    @Autowired
    private SessionFactory sessionFactory;
    @Override
    public List<UpholsteryType> getUpholsteryTypeList() {

        Session session = sessionFactory.openSession();
        String hql="from UpholsteryType";
        List list = session.createQuery(hql).list();
        session.close();
        return list;


    }

    @Override
    public List<TemporaryCarParts> getTemporaryCarPartsList(Integer equipmentSheetNo) {

        Session session = sessionFactory.openSession();
        List list = session.createQuery("from TemporaryCarParts where equipmentSheetNo=:equipmentSheetNo").setParameter("equipmentSheetNo", equipmentSheetNo).list();
        session.close();
        return list;


    }

    @Override
    public Integer getMaxCustomerId() {
        Session session = sessionFactory.openSession();
        Object o = session.createQuery("select max(customerId) from Customer").uniqueResult();
        session.close();
        if (o==null){
            return 0;
        }
        return (Integer) o;
    }
}
